#ifndef SKYROAD_CONNECTION_MANAGER_H_
#define SKYROAD_CONNECTION_MANAGER_H_

#include <hash_map>
#include <boost/noncopyable.hpp>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/unordered_map.hpp>

#include "connection.hpp"

class connection_manager : private boost::noncopyable 
{
public:
    connection_manager();

    virtual ~connection_manager();

    void start(connection_ptr& c);

    void stop(connection_ptr& c);

    void stop_all();

    connection_ptr get(int id);

    void start_gc_thread();
protected:

    void gc_loop();

    void gc();

private:
    bool m_active;


    typedef boost::unordered_map<int, connection_ptr>::iterator mapit;

    boost::unordered_map<int, connection_ptr> m_connections;

    boost::mutex m_mutex;

    boost::shared_ptr<boost::thread> m_gc_thread;
};
#endif